<?php
require_once(dirname(__FILE__)."/../lib/Loader.php");
cfgload("defines");
cfgload("distr");
cload("Smarty.smartyRenderer");
cload("requestProcessor");
cload("kinopoisk.kinoPoiskFilm");
cload("distr.distribution");

/**
 * Description of distrForm
 *
 * @author Di_Moon
 */
class distrForm extends smartyRenderer {
    protected $_dbh;
    protected $_filmid;
    protected $_id;
            
    function __construct($dbh) {
        parent::__construct();
        $this->_dbh = $dbh;
        
        $this->_filmid = requestProcessor::getVar("filmid");
        $this->_id = requestProcessor::getVar("id", 0);
        $this->assign("distrTypes", _distr_Types());
        $this->assign("distrStatutes", _distr_statusArray());
        $this->assign("filmid", $this->_filmid);
    }
    
    function render() {
        $distr = new distribution($this->_dbh, $this->_id);
        $distr->load();
        
        if(requestProcessor::getVar("action")=="form") {
            $post = requestProcessor::post();
            
            $distr->set("filmid", $this->_filmid);
            $distr->set("type", $post->get("type"));
            $distr->set("status", $post->get("status"));
            $distr->set("url", $post->get("url"));
            
            $distr->save();
            
            header("Location: ".$_SERVER["SCRIPT_NAME"]."?a=distrList&filmid=".$this->_filmid);
            exit();
        }
        
        $this->assign("d_id", $this->_id);
        $this->assign("d_type", $distr->get("type"));
        $this->assign("d_status", $distr->get("status"));
        $this->assign("d_url", $distr->get("url"));
        
        return $this->fetch("distrForm.tpl");
    }
}

?>
